<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Web 安全攻击与防御</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
        }
        .code-block pre {
            margin: 0;
            padding: 1.5rem;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 0.875rem;
            line-height: 1.5;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, transparent);
            margin: 3rem 0;
        }
        .attack-icon {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .defense-icon {
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-4">Web 安全攻击与防御</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">深入理解 SQL 注入与 CSRF 攻击的原理与防护策略</p>
            <div class="flex justify-center space-x-8 text-3xl">
                <i class="fas fa-shield-alt"></i>
                <i class="fas fa-lock"></i>
                <i class="fas fa-user-shield"></i>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-6xl">
        
        <!-- SQL Injection Section -->
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 mb-12 card-hover">
            <div class="flex items-center mb-6">
                <i class="fas fa-database text-4xl attack-icon mr-4"></i>
                <h2 class="text-3xl md:text-4xl font-bold text-gray-800">SQL 注入攻击</h2>
            </div>
            
            <p class="text-lg text-gray-700 leading-relaxed mb-8">
                <span class="drop-cap">S</span>QL 注入攻击是一种通过将恶意 SQL 代码插入到应用程序的输入字段或查询字符串中，来操控数据库执行未授权的 SQL 查询的攻击方法。攻击者可以利用 SQL 注入漏洞来绕过身份验证、读取、修改或删除数据库中的数据，甚至执行系统命令。
            </p>

            <!-- 工作原理 -->
            <div class="mb-10">
                <h3 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                    <i class="fas fa-cogs text-purple-600 mr-3"></i>
                    工作原理
                </h3>
                
                <div class="grid md:grid-cols-3 gap-6 mb-8">
                    <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl">
                        <div class="text-3xl text-purple-600 mb-3">
                            <i class="fas fa-keyboard"></i>
                        </div>
                        <h4 class="font-semibold text-lg mb-2">1. 输入注入</h4>
                        <p class="text-gray-700">攻击者通过输入字段（如登录表单、搜索框）注入恶意的 SQL 代码。</p>
                    </div>
                    
                    <div class="bg-gradient-to-br from-blue-50 to-indigo-50 p-6 rounded-xl">
                        <div class="text-3xl text-blue-600 mb-3">
                            <i class="fas fa-link"></i>
                        </div>
                        <h4 class="font-semibold text-lg mb-2">2. SQL 拼接</h4>
                        <p class="text-gray-700">应用程序将用户输入的内容直接拼接到 SQL 查询中。</p>
                    </div>
                    
                    <div class="bg-gradient-to-br from-red-50 to-orange-50 p-6 rounded-xl">
                        <div class="text-3xl text-red-600 mb-3">
                            <i class="fas fa-exclamation-triangle"></i>
                        </div>
                        <h4 class="font-semibold text-lg mb-2">3. 恶意执行</h4>
                        <p class="text-gray-700">未经处理的恶意 SQL 代码被执行，导致数据库泄漏或被破坏。</p>
                    </div>
                </div>

                <div class="code-block mb-8">
                    <pre><code>SELECT * FROM users WHERE username = 'user_input' AND password = 'pass_input';</code></pre>
                </div>
            </div>

            <!-- 攻击示例 -->
            <div class="mb-10">
                <h3 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                    <i class="fas fa-bug text-red-600 mr-3"></i>
                    常见攻击示例
                </h3>
                
                <div class="space-y-4">
                    <div class="flex items-start">
                        <i class="fas fa-user-times text-red-500 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold">认证绕过</h4>
                            <p class="text-gray-700">通过注入 <code class="bg-gray-100 px-2 py-1 rounded">' OR '1'='1</code> 这样的代码绕过登录验证。</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <i class="fas fa-database text-red-500 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold">数据泄露</h4>
                            <p class="text-gray-700">通过注入 <code class="bg-gray-100 px-2 py-1 rounded">'; SELECT * FROM sensitive_data; --</code> 查询敏感数据表。</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <i class="fas fa-edit text-red-500 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold">数据篡改</h4>
                            <p class="text-gray-700">通过注入 <code class="bg-gray-100 px-2 py-1 rounded">'; UPDATE users SET role = 'admin'; --</code> 更改数据。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 防御措施 -->
            <div>
                <h3 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                    <i class="fas fa-shield-alt defense-icon mr-3"></i>
                    防御措施
                </h3>
                
                <div class="space-y-6">
                    <div class="bg-blue-50 p-6 rounded-xl">
                        <h4 class="font-semibold text-lg mb-3 flex items-center">
                            <i class="fas fa-code text-blue-600 mr-2"></i>
                            使用参数化查询
                        </h4>
                        <p class="text-gray-700 mb-4">避免直接拼接 SQL 语句，而是使用预编译的 SQL 语句和参数化查询。</p>
                        <div class="code-block">
                            <pre><code>PreparedStatement ps = connection.prepareStatement(
    "SELECT * FROM users WHERE username = ? AND password = ?"
);
ps.setString(1, username);
ps.setString(2, password);
ResultSet rs = ps.executeQuery();</code></pre>
                        </div>
                    </div>
                    
                    <div class="bg-green-50 p-6 rounded-xl">
                        <h4 class="font-semibold text-lg mb-3 flex items-center">
                            <i class="fas fa-filter text-green-600 mr-2"></i>
                            输入验证与清理
                        </h4>
                        <p class="text-gray-700">对用户输入进行严格的验证和清理，避免接受和执行非法的输入。</p>
                    </div>
                    
                    <div class="bg-yellow-50 p-6 rounded-xl">
                        <h4 class="font-semibold text-lg mb-3 flex items-center">
                            <i class="fas fa-user-lock text-yellow-600 mr-2"></i>
                            最小权限原则
                        </h4>
                        <p class="text-gray-700">数据库账户应具有最小权限，只能执行必要的操作，减少潜在的损害。</p>
                    </div>
                </div>
            </div>
        </div>

        <div class="section-divider"></div>

        <!-- CSRF Section -->
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 mb-12 card-hover">
            <div class="flex items-center mb-6">
                <i class="fas fa-user-secret text-4xl attack-icon mr-4"></i>
                <h2 class="text-3xl md:text-4xl font-bold text-gray-800">CSRF 攻击</h2>
            </div>
            
            <p class="text-lg text-gray-700 leading-relaxed mb-8">
                <span class="drop-cap">C</span>SRF 攻击是一种欺骗用户的攻击方式，通过伪造用户的请求来诱使用户执行他们未授权的操作。攻击者利用用户的身份认证信息（如 Cookie）在用户不知情的情况下发起恶意请求，从而执行未授权的操作。
            </p>

            <!-- 工作原理 -->
            <div class="mb-10">
                <h3 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                    <i class="fas fa-cogs text-purple-600 mr-3"></i>
                    工作原理
                </h3>
                
                <div class="grid md:grid-cols-2 gap-6 mb-8">
                    <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl">
                        <div class="text-3xl text-purple-600 mb-3">
                            <i class="fas fa-mask"></i>
                        </div>
                        <h4 class="font-semibold text-lg mb-2">1. 请求伪造</h4>
                        <p class="text-gray-700">攻击者创建恶意网页或电子邮件，包含伪造的请求，利用受害者的认证信息发送到目标网站。</p>
                    </div>
                    
                    <div class="bg-gradient-to-br from-red-50 to-orange-50 p-6 rounded-xl">
                        <div class="text-3xl text-red-600 mb-3">
                            <i class="fas fa-bomb"></i>
                        </div>
                        <h4 class="font-semibold text-lg mb-2">2. 恶意操作</h4>
                        <p class="text-gray-700">受害者在登录状态下访问恶意网页，伪造的请求被发送，执行未授权的操作。</p>
                    </div>
                </div>
            </div>

            <!-- 攻击流程图 -->
            <div class="mb-10">
                <h3 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                    <i class="fas fa-project-diagram text-indigo-600 